<?php 
//**** SITE FUNCTIONS ****//
function industry($industry,$industry_other_text='')	// industry
{
	$industry=explode(",",$industry);
	$sqlPLI = " select * from tbl_industry where status = '1' order by industry asc";
	$resPLI = executeQuery($sqlPLI);
	$i=0;
		echo "<input type='checkbox' name='industry_any' value='any' onClick='getElements(this)' />&nbsp;&nbsp;Any<br /> ";
	while($lineI=mysql_fetch_array($resPLI))
	{
		$i++;
		$industry1 = "$industry".$i;
	
		echo "<input type='checkbox' name='industry[]' value='$lineI[industry]' ";
		if($industry)
		{
			$industry1= $industry; 
			while (list($key, $val) = each($industry1))
			{ 
				if ($val == $lineI['industry']) 
				{ 
					echo "checked"; 
				}
			}
		}
		echo "/>&nbsp;&nbsp;".$lineI['industry']."<br />"; 
	}
	echo "<input type='checkbox' name='industry_other' value='other' /> &nbsp;Other&nbsp;&nbsp;&nbsp;&nbsp;<input name='industry_other_text' type='text' class='inpr3' value='$industry_other_text' />";
}

function functionalArea($functionalArea,$functional_area_other_text='')	// industry
{
	$functionalArea=explode(",",$functionalArea);
	$sqlPLF = " select * from tbl_functionalArea where status = '1' order by functionalArea asc";
	$resPLF = executeQuery($sqlPLF);
	$j=0;
		echo "<input type='checkbox' name='functionalArea_any' value='any' onClick='getElements1(this)' />&nbsp;&nbsp;Any<br /> ";
	while($lineF=mysql_fetch_array($resPLF))
	{
		$j++;
		$functionalArea1 = "$functionalArea".$j;
		echo "<input type='checkbox' name='functionalArea[]' value='$lineF[functionalArea]' ";
		if($functionalArea)
		{
			$functionalArea1= $functionalArea; 
			while (list($key, $val) = each($functionalArea1))
			{ 
				if ($val == $lineF['functionalArea']) 
				{ 
					echo "checked"; 
				}
			}
		}
		echo "/>&nbsp;&nbsp;".$lineF['functionalArea']."<br />"; 
	}
	echo "<input type='checkbox' name='functional_area_other' value='other' /> &nbsp;Other&nbsp;&nbsp;&nbsp;&nbsp;<input name='functional_area_other_text' type='text' class='inpr3' value='$functional_area_other_text' />";
}


function validate_admin()	// Admin Validation
{
	if($_SESSION['sess_admin_id'] == '')
	{
		$_SESSION['sessMsg'] = " Please login to administration suit. "; 
		header("location: index.php");
		exit();
	}
}
function validate_admin_system()	// Admin Validation
{
	if($_SESSION['sess_admin_id'] == '')
	{
		unset($_SESSION['type_user']);
		$_SESSION['sessMsg'] = " Please login first. "; 
		header("location: ../_admincms/index.php");
		exit();
	}
}
//------------------- Appraiser Validation -------------//
function validate_admin_system_user()	// Admin Validation
{
	if($_SESSION['sess_admin_id'] == '' || $_SESSION['type_user'] == '')
	{
		$_SESSION['go'] = $_SERVER['PHP_SELF'];
		if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
		$_SESSION['sessMsg'] = " You need to login first. ";
		header("location: login.php");
		exit();
	}
}
function validate_admin_system_lender()	// Lender Validation
{
	if($_SESSION['sess_admin_id'] == '' || $_SESSION['type_user'] == '')
	{
		$_SESSION['go'] = $_SERVER['PHP_SELF'];
		if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
		$_SESSION['sessMsg'] = " You need to login first. ";
		header("location: loginLender.php");
		exit();
	}
}
function validate_admin_system_appraiser()	// Appraiser Validation
{
	if($_SESSION['sess_admin_id'] == '' || $_SESSION['type_user'] == '')
	{
		$_SESSION['go'] = $_SERVER['PHP_SELF'];
		if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
		$_SESSION['sessMsg'] = " You need to login first. ";
		header("location: loginAppraiser.php");
		exit();
	}
}
function validate_admin_system_employee()	// Lender Employee
{
	if($_SESSION['sess_admin_id'] == '' || $_SESSION['type_user'] == '')
	{
		$_SESSION['go'] = $_SERVER['PHP_SELF'];
		if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
		$_SESSION['sessMsg'] = " You need to login first. ";
		header("location: loginEmployee.php");
		exit();
	}
}
//---------------------- END -------------------------//
function validate_admin_practitioner()	//  Practitioner admin Validation
{
	if(!$_SESSION['sess_id'])
	{
		if($_POST)
			{
				$_SESSION['post_value']=$_POST;
			}
		$_SESSION['go'] = $_SERVER['PHP_SELF'];
		if($_SERVER['QUERY_STRING']){ $_SESSION['go'].="?".$_SERVER['QUERY_STRING']; }
		$_SESSION['sessMsg'] = " You need to login first. "; 
		header("location:index.php");
		exit();
	}
	
}
function validate_practitioner()	//  Practitioner  Validation
{
	if(!$_SESSION['insertUserId'])
	{
		$_SESSION['sessMsg'] = " You need to register to access this Page. "; 
		header("location:index.php");
		exit();
	}
	
}
function executeQuery($query) {
global $LOCAL_MODE;
global $SUPPORT_EMAIL;
global $SITE_SUPPORT;
global $SITE_FULL_NAME;
	/*$temp = mysql_query($query) or die("<font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font>");*/
	if($LOCAL_MODE) 
		{
			$temp = mysql_query($query) or die("<font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font>");
		}
	else
		{
			$tm = mysql_query($query);
			if($tm) {
			$temp = $tm;
			}
			else {
			$errMsg="There is an error encountered in ".$SITE_FULL_NAME."<br><font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font> on Page : ".$_SERVER['PHP_SELF'];
			send_mail($SUPPORT_EMAIL,$subject='Error Message',$errMsg,$SITE_SUPPORT,'Error Message',$html=true);
			header("location:mantinancePage.php");
			exit();
			}
		}
	return $temp;
}

function executeUpdate($query) {
	$temp = mysql_query($query) or die("<font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font>");
}

function getSingleResult($query)
{
$response = "";	
global $LOCAL_MODE;
global $SUPPORT_EMAIL;
global $SITE_SUPPORT;
global $SITE_FULL_NAME;
	if($LOCAL_MODE) 
		{
			$result = mysql_query($query) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".$query."<br><br>".mysql_error()."'</center>");
			if ($line = mysql_fetch_array($result)) {
				$response = $line[0];
			}
		}
	else
		{
			$tm = mysql_query($query);
			if($tm) {
			if ($line = mysql_fetch_array($tm)) {
				$response = $line[0];
			} 
			}
			else {
			$errMsg="There is an error encountered in ".$SITE_FULL_NAME."<br><font size=2 color=red>You have an error(<font color=black>". mysql_error() . "</font>) in executing query : " . $query . " in file " . __FILE__ . " at line " . __LINE__ . "</font> on Page : ".$_SERVER['PHP_SELF'];
			send_mail($SUPPORT_EMAIL,$subject='Error Message',$errMsg,$SITE_SUPPORT,'Error Message',$html=true);
			header("location:mantinancePage.php");
			exit();
			}
		}
	return $response;
}
function check_input($value){
	$value = stripslashes($value);
	$value = addslashes($value);
	return $value;
} 

function displaySessMesg(){
	if(stristr($_SERVER['PHP_SELF'], 'admincms')){
		$class = 'sessMsg';
	}else{
		$class='dis-Msg';
	}	

	$msg = '<table cellpadding="2" cellspacing="2" border="0" align="center">
	<tr>
		<td class="'.$class.'" height="25" >'.$_SESSION['sessMsg'].'</td>
	</tr>
	</table>';

	if($_SESSION['sessMsg']!= ''){
		echo $msg;
		$_SESSION['sessMsg'] = "";
	}
}

function displaySessMesg1()
{
	
	if(stristr($_SERVER['PHP_SELF'], 'admincms'))
		{
			$class = 'sessMsg';
		}
	else
		{
			$class='heading-msg';
		}	
	$msg = "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" >
	<tr>
		<td class='errtxt height='25' >$_SESSION[sessMsg]</td>
	</tr>
	</table>";
	if($_SESSION['sessMsg']!= '')
	{
		echo $msg;
		$_SESSION['sessMsg'] = "";
	}
}
function getSellerIdByProductId($Id)
 {
  $sql="select sellerId from tbl_product where productId='$Id'";
  $result=getSingleResult($sql);
  return $result;
 }
function getSpawAdvEditor11($field_name, $field_value='', $width,$height,$class='')
{	
	$sw = new SPAW_Wysiwyg($field_name, $field_value, 'en', 'full', 'default', $width, $height, '',  '');
	$sw->show();
}

function getSpawAdvEditor($field_name, $field_value='', $width, $height)
{	
$sBasePath = $_SERVER['PHP_SELF'] ;

$isAdmin = strpos($sBasePath,"admincms");
$isPractitionerAdmin = strpos($sBasePath,"admin");
if($isAdmin == true)
{
	$editorBasePath = "./fckeditor/";
}
else if($isPractitionerAdmin==true)
{
	$editorBasePath = "../admincms/fckeditor/";
}
else
{
	$editorBasePath = "./admincms/fckeditor/";
	
}

$oFCKeditor = new FCKeditor($field_name) ;
//$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->BasePath	= $editorBasePath;
$oFCKeditor->ToolbarSet = "Default";
$oFCKeditor->Height		= $height ;
$oFCKeditor->Width		= $width ;
$oFCKeditor->Value		=  $field_value ;

$oFCKeditor->Create() ;

}

function getSpawEditor($field_name, $field_value='', $width,$height,$class='')
{	
	$sw = new SPAW_Wysiwyg($field_name, $field_value, 'en', 'mini', 'default', $width, $height, '',  '');
	$sw->show();
}
function dopaging($sql,$limit)
{
	global $nume ;
	global $pagingLimit  ;
	$pagingLimit  = $limit ;
	if($_REQUEST[nop])
	 {
		$start=$pagingLimit*$_REQUEST[nop]-$pagingLimit;
	 }
	else
	 {
		$start=0;
	 }              
	$row=executeQuery($sql);
	$nume=mysql_num_rows($row);
	$sql = "$sql limit $start, $pagingLimit";
	return $sql;
}
function rightPaging()
{
global $nume ;
global $pagingLimit ;
$pageName = basename($_SERVER['PHP_SELF']);
	 $str = "";
	 foreach( $_GET as $key=>$value)
	  {
	    if ($key=="nop")
		{}
		else
		 $str = $str."&".$key."=".$value;
	   }	  
	 foreach( $_POST as $key=>$value)
	  {
	    if ($key=="nop")
		{}
		else
		 $str = $str."&".$key."=".$value;
	   }	  
$pN = $_GET['nop'];
if($nume%$pagingLimit)
		{
			$nop=$nume/$pagingLimit;
			$nop=ceil($nop);
		}
	else
		{
			$nop=$nume/$pagingLimit;
		}
		
	for($n=1;$n<=$nop;$n++) 
	{
		if(($pN==$n) || ($n=='1' && !$pN && $nop!=1)) 
		{ 
			echo "<span class=\"nrml-txt4\">$n</span>&nbsp;&nbsp;"; 
		} 
		else
		{
			echo "<a href=\"$pageName?nop=$n&$str\"  class=\"toplink\"><u>";
			 if($nop>1) 
			{
				echo $n; 
			}
			echo "</u></a>&nbsp;&nbsp;";
		 } 
	}
}

function rightPagingFront()
{
global $nume ;
global $pagingLimit ;
$pageName = basename($_SERVER['PHP_SELF']);
	 $str = "";
	 foreach( $_GET as $key=>$value)
	  {
	    if ($key=="nop")
		{}
		else
		 $str = $str."&".$key."=".$value;
	   }	  
	 foreach( $_POST as $key=>$value)
	  {
	    if ($key=="nop")
		{}
		else
		 $str = $str."&".$key."=".$value;
	   }	  
$pN = $_GET['nop'];
if($nume%$pagingLimit)
		{
			$nop=$nume/$pagingLimit;
			$nop=ceil($nop);
		}
	else
		{
			$nop=$nume/$pagingLimit;
		}
		
	for($n=1;$n<=$nop;$n++) 
	{
		if(($pN==$n) || ($n=='1' && !$pN && $nop!=1)) 
		{ 
			echo "<span class=\"nrml-txt4\">$n</span>&nbsp;&nbsp;"; 
		} 
		else
		{
			echo "<a href=\"?nop=$n&$str\"  class=\"toplink\"><u>";
			 if($nop>=1) 
			{
				echo $n; 
			}
			echo "</u></a>&nbsp;&nbsp;";
		 } 
	}
}

function isFieldDuplicate($tableName='',$fieldName='',$filedValue='',$autoIdName='',$autoIdValue='',$isNullAllowed=false,$extra='')
{
	$sql = " select * from $tableName where $fieldName = '$filedValue'";
	if($autoIdName != '' and $autoIdValue != '')
	{
		$sql.= " and $autoIdName != '$autoIdValue' " ;
	}
	if($extra != '')
	{
		$sql.=" $extra ";
	}
	//echo $sql; exit;
	$isDuplicate = getSingleResult($sql);
	if($isNullAllowed and $filedValue == '')
	{
		$isDuplicate = false ;
	}
	if($isDuplicate)
	{
		return true ;
	}
	else 
	{
		return false ;
	}
}
function isPageDuplicate($tableName='',$fieldName='',$filedValue='',$autoIdName1='',$autoIdValue1='',$autoIdName2='',$autoIdValue2='',$isNullAllowed=false,$extra='')
{
	$sql = " select * from $tableName where $fieldName = '$filedValue'";
	if($autoIdName1 != '' and $autoIdValue1 != '')
	{
		$sql.= " and $autoIdName1 != '$autoIdValue1' " ;
	}
	if($autoIdName2 != '' and $autoIdValue2 != '')
	{
		$sql.= " and $autoIdName2 ='$autoIdValue2' " ;
	}
	if($extra != '')
	{
		$sql.=" $extra ";
	}
	//echo $sql; exit;
	$isDuplicate = getSingleResult($sql);
	if($isNullAllowed and $filedValue == '')
	{
		$isDuplicate = false ;
	}
	if($isDuplicate)
	{
		return true ;
	}
	else 
	{
		return false ;
	}
}
function isFieldDuplicateSimple($tableName='',$fieldName='',$filedValue='')
{
	$sql = " select * from $tableName where $fieldName = '$filedValue'";
	//echo $sql; exit;
	$isDuplicate = getSingleResult($sql);
	if($isNullAllowed and $filedValue == '')
	{
		$isDuplicate = false ;
	}
	if($isDuplicate)
	{
		return true ;
	}
	else 
	{
		return false ;
	}
}


function send_mail($email_to,$subject,$message,$from_email,$from_name='',$html=false)
{

	if($from_name == '') 
	{	
		$from_name=$from_email;
	}
	$headers1= ""; 
	if($html) 
	{
		$headers1.= "Content-type: text/html; charset=iso-8859-1\r\n";
	}
	else 
	{
		$headers1.= "Content-type: text/plain; charset=iso-8859-1\r\n";
	}
	
	$headers1.= "From: $from_email\r\n";
	@mail($email_to,$subject,$message,$headers1);
}
function getPageContent($pageId)
{
	if($pageId != '')
	{
		$sql = " select * from tbl_pages where status = '1' and pageId = '$pageId' ";
		$res = executeQuery($sql);
		if($row = mysql_fetch_array($res))
		{
			$arrPageContent['pageName'] = $row['pageName'];
			$arrPageContent['pageHeading'] = $row['pageHeading'];
			$arrPageContent['pageContent'] = $row['pageContent'];
			return $arrPageContent ;
		}
	}
}
function getEditPageContent($pageId,$userId)
{
	if($pageId != '')
	{
		$sql = " select * from tbl_user_page where status = '1' and pageLinkId = '$pageId' && userId='$userId' ";
		$res = executeQuery($sql);
		if($row = mysql_fetch_array($res))
		{
			$arrPageContent['pageName'] = $row['pageName'];
			$arrPageContent['pageHeading'] = $row['pageHeading'];
			$arrPageContent['pageContent'] = $row['pageContent'];
			return $arrPageContent ;
		}
	}
}
function getAdminPageContent($page)
{
	if($page != '')
	{
		$sql = " select * from tbl_admin_pages where adminPageId = '$page' ";
		$res = executeQuery($sql);
		if($row = mysql_fetch_array($res))
		{
			$arrPageContent['pageName'] = $row['adminPageName'];
			$arrPageContent['pageContent'] = $row['adminPageContent'];
			return $arrPageContent ;
		}
	}
}


function getCombo($arrName,$comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$combo="<select name='$comboName' id='$comboName' $extra ";
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>-- Select Any --</option>";
	foreach($arrName as $key=>$value)		
	{
		if ($selectedValue == $key) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$key' $selectedText > $value </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getDomainCombo($arrName,$comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$combo="<select name='$comboName' id='$comboName' $extra ";
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	foreach($arrName as $key=>$value)		
	{
		if ($selectedValue == $key) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$key' $selectedText > $value </option>";
	}
	$combo.="</select>";
	return $combo ;
}

function getComboSimple($arrName,$comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$combo="<select name='$comboName' id='$comboName' $extra ";
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	//$combo.="<option value='' selected>-- Select Any --</option>";
	foreach($arrName as $key=>$value)		
	{
		if ($selectedValue == $key) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$key' $selectedText > $value </option>";
	}
	$combo.="</select>";
	return $combo ;
}

function resizeImg($imgPath, $maxWidth, $maxHeight, $directOutput = true, $quality = 90, $verbose,$imageType)

{

  

   // get image size infos (0 width and 1 height,

   //     2 is (1 = GIF, 2 = JPG, 3 = PNG)

     $size = getimagesize($imgPath);



   // break and return false if failed to read image infos

     if(!$size){

       if($verbose && !$directOutput)echo "<br/> Not able to read image infos.<br />";

       return false;

     }



   // relation: width/height

     $relation = $size[0]/$size[1];

   // maximal size (if parameter == false, no resizing will be made)

     $maxSize = array($maxWidth?$maxWidth:$size[0],$maxHeight?$maxHeight:$size[1]);

   // declaring array for new size (initial value = original size)

     $newSize = $size;

   // width/height relation

     $relation = array($size[1]/$size[0], $size[0]/$size[1]);





	if(($newSize[0] > $maxWidth))

	{

		$newSize[0]=$maxSize[0];

		$newSize[1]=$newSize[0]*$relation[0];

	}

	

	if(($newSize[1] > $maxHeight))

	{

		$newSize[1]=$maxSize[1];

		$newSize[0]=$newSize[1]*$relation[1];

	}



     // create image



       switch($size[2])

       {

         case 1:

           if(function_exists("imagecreatefromgif"))

           {

             $originalImage = imagecreatefromgif($imgPath);

           }else{

             if($verbose && !$directOutput)echo "<br />No GIF support in this php installation, sorry.<br />";

             return false;

           }

           break;

         case 2: $originalImage = imagecreatefromjpeg($imgPath); break;

         case 3: $originalImage = imagecreatefrompng($imgPath); break;

         default:

           if($verbose && !$directOutput)echo "<br />No valid image type.<br />";

           return false;

       }





     // create new image
	$newSize[0]=$maxWidth;
    $newSize[1]=$maxHeight;

       $resizedImage = imagecreatetruecolor($newSize[0], $newSize[1]); 



       imagecopyresampled($resizedImage, $originalImage,0, 0, 0, 0,$newSize[0], $newSize[1], $size[0], $size[1]);



	$rz=$imgPath;



     // output or save

       if($directOutput)

		{

         imagejpeg($resizedImage);

		 }

		 else

		{

			

			 $rz=preg_replace("/\.([a-zA-Z]{3,4})$/","".$imageType.".jpg",$imgPath);

			 imagejpeg($resizedImage, $rz, $quality);

         }

     // return true if successfull

       return $rz;

}
function getThumbName($picName,$type='')
{
	if($type == '')
	{
		$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb.jpg",$picName);
	}
	/*elseif($type == '2')
	{
		$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb2.jpg",$picName);
	}
	elseif($type == '3')
	{
		$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb3.jpg",$picName);
	}
	elseif($type == '4')
	{
		$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb4.jpg",$picName);
	}
	elseif($type == '5')
	{
		$thumbName = preg_replace("/\.([a-zA-Z]{3,4})$/","_thumb5.jpg",$picName);
	}*/
	return $thumbName; 
}

function imgUpload($input,$location,$isThumb=false,$thWidth=100,$thHeight=100,$maxWidth='',$maxHeight='',$maxSize='',$chkExt='')
{
	$flag=false;
	$return = array();
	if($input['name']=="")
	{
		$return[0]=false;
		$return[1]="File name not found in form object!";
		return $return;
	}
	else if($maxWidth!="" && $maxHeight!="")
	{
		list($w,$h,$type,$att)=@getimagesize($input['tmp_name']);
		if($w >= $maxWidth && $h >= $maxHeight)
		{
			$flag=true;
		}
		else
		{
			$return[0]=false;
			$return[1]="Image width or height did not match. Image size should be greater than or equal to ".$maxWidth."x".$maxHeight." !";
			return $return;
		}
	}
	else if($maxSize!="")
	{
		if($input['size'] <= $maxSize )
		{
			$flag=true;
		}
		else
		{
			$return[0]=false;
			$return[1]="Image size exceed than maximum size=".$maxSize." !";
			return $return;
		}
	}
	else
	{
		$flag=true;
	}
	
	if($flag)
	{	
		// echo $location;
		if(!is_dir($location))
		{		
			mkdir($location,0777);
		}

		$Ext=explode(".",$input['name']);
		$ext=$Ext[count($Ext)-1];
		
		if(is_array($chkExt))
		{
			
			if(in_array(strtolower($ext),$chkExt))
			{
				$ranno1=getRandomStr(7);
				$filen=$ranno1.".".$ext;
				$filename=$location.$ranno1.".".$ext;
				$tempfile=$input['tmp_name'];
				if(!copy($tempfile,$filename)) 
				{
					$return[0]=false;
					$return[1]="Problem in file. Cannot be copied!";
					return $return;
				}
				if($isThumb)
				{
					$image = resizeImg($filename, $thWidth ,$thHeight, false, 100, 0,"_thumb"); //100x120
					//$image = resizeImg($filename, '170' , '116', false, 100, 0,"_thumb2");
					//$image = resizeImg($filename, '157' , '188', false, 100, 0,"_thumb3");
					//$image = resizeImg($filename, '100' , '80', false, 100, 0,"_thumb4");
					//$image = resizeImg($filename, '300' , '200', false, 100, 0,"_thumb5");
				}
				
				$return[0]=true;
				$return[1]=$filen;
				$return[2]=$ranno1."_thumb.jpg";
				return $return;
			}
			else
			{
				$strExt = @implode(",",$chkExt);
				$return[0]=false;
				$return[1]="Please upload valid file. You can only upload file with extension ".$strExt;
				return $return;
			}
		}
	}
}

function getRandomStr($length) {
	// if you want extended ascii, then add the characters to the array
	$characters = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
	$random_str = "";
	for ($i = 0; $i < $length; $i++) {
		srand((double)microtime()*1000000);
		$random_chr = round(rand(0, count($characters)-1));
		$random_str .= $characters[$random_chr];
	}
	return ($random_str);
}
function getRandomStrInt($length) {
	// if you want extended ascii, then add the characters to the array
	$characters = array('0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9');
	$random_str = "";
	for ($i = 0; $i < $length; $i++) {
		srand((double)microtime()*1000000);
		$random_chr = round(rand(0, count($characters)-1));
		$random_str .= $characters[$random_chr];
	}
	return ($random_str);
}
function concatSql($isSql=false,$sqlVal='',$tblField='',$requestField='',$method='',$whCondition='and',$whOpreator='=')
{
	if($isSql)
	{
		$sql= $sqlVal ;	
	}
	else
	{
		if($tblField != '' && $requestField != '' && $method != '')
		{
			$arrMethod = array
			(
			'get'=>$_GET[$requestField],
			'post'=>$_POST[$requestField],
			'request'=>$_REQUEST[$requestField]
			);

			$tmpVar = $arrMethod[$method];			

			if($tmpVar != '')
			{
				if($whOpreator == 'like')
				{
					$sql = $whCondition." ".$tblField." ".$whOpreator." '%".$tmpVar."%' ";
				}
				else
				{
					$sql = $whCondition." ".$tblField." ".$whOpreator." '".$tmpVar."' ";
				}
			}
		}
	}
	
	return $sql;
}
 
 

function getImage($table='',$field='',$userId='',$attributeId='')
	{
		$sql = " select  $field from $table where attributeId='$attributeId' && userId='$userId' ";
		$result = getSingleResult($sql );
		return $result;
	}
	
	 
function displayImage($tblname='',$fieldname='',$condition='',$messageType='',$path='')
	{
		$sql = " select $fieldname from $tblname ";
		if($condition)
			{
			 	$sql.= " where  $condition ";
			}
	 $result = getSingleResult($sql);
			if($result)
			{
				$show = '<img src="'.$path."/".$result.'" hight="100" width="150"/>';
			}
		else
			{
				if($messageType == 'D')
					{
						$show = '<img src="images/4lw6vj7.jpg" hight="100" width="150"/>';
					}
				else
					{
						$show ='<span class="redtxt"> !Sorry No Image Uploaded.</span>';
					}	
			}	
		return $show;	
	}
function getAdmin()
{
$sqlQr="select email from tbl_admin";
$result=executeQuery($sqlQr);
$row=mysql_fetch_array($result);
return $row;
}
function getCountryCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_country order by country asc";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['countryId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[countryId]' $selectedText >$row[country] </option>";
	}
	$combo.="</select>";
	return $combo ;
}

function getCategoryCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_category order by name asc";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['id']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[id]' $selectedText >$row[name] </option>";
	}
	$combo.="</select>";
	return $combo ;
}

function getUserCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_user where email!='' order by firstName asc";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['userId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[userId]' $selectedText >$row[email] - $row[firstName] $row[lastName]</option>";
	}
	$combo.="</select>";
	return $combo ;
}

function getFunctionalAreaCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_functionalArea order by functionalArea asc";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['functionalArea']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[functionalArea]' $selectedText >$row[functionalArea] </option>";
	}
	$combo.="</select>";
	return $combo ;
}

function getPackageCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_package where status=1 order by packageId asc";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['packageId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[packageId]' $selectedText >$row[title]--Amount $$row[amount]</option>";
	}
	$combo.="</select>";
	return $combo ;
}

/*
function getCategoryCombo($comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$sql = " select * from tbl_category where parentId='0'  ";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Category ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['categoryId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[categoryId]' $selectedText > $row[category] </option>";
	}
	$combo.="</select>";
	return $combo ;
}
*/
function getCompanyCombo($comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$sql = " select * from tbl_lendercompany where status='1' && adminId='$_SESSION[adminId]'  ";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Company ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['lenderCompanyId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[lenderCompanyId]' $selectedText > $row[companyName] </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getLenderCompanyCombo($comboName='',$class='',$selectedValue = '', $lenderId = '') 
{
	$sql = " select * from tbl_lendercompany A, tbl_lender B where A.lenderCompanyId=B.lenderCompanyId &&  A.adminId='$_SESSION[adminId]' && lenderId='$lenderId'  ";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	//$combo.="<option value='' selected>--- Select Company ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['lenderCompanyId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[lenderCompanyId]' $selectedText > $row[companyName] </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getAppraiserCombo($comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$sql = " select * from tbl_appraiser where status='1' && adminId='$_SESSION[adminId]' order by APFirstName  ";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Appraiser ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['appraiserId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[appraiserId]' $selectedText >".$row['APFirstName']." ".$row['APLastName']." </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getAppraiserByStateCombo($comboName='',$class='',$selectedValue = '', $extra = '',$state) 
{
	$sql = " select * from tbl_appraiser A ,tbl_appraiserstate B where  A.appraiserId=B.appraiserId && A.status='1' && state='$state' && adminId='$_SESSION[adminId]'  ";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Appraiser ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['appraiserId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[appraiserId]' $selectedText >".$row['APFirstName']." ".$row['APLastName']." </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getAppraiserByZipCombo($comboName='',$class='',$selectedValue = '', $extra = '',$zip) 
{
	$sql = " select * from tbl_appraiser A ,tbl_appraiserstate B where  A.appraiserId=B.appraiserId && A.status='1' && (FIND_IN_SET('$zip', zipcodes) || FIND_IN_SET(' $zip', zipcodes)) && adminId='$_SESSION[adminId]'";
	$res = executeQuery($sql);
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Appraiser ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['appraiserId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		//if(($_SESSION['sess_id']==$row['sellerId'] && $_SESSION['sess_id']==$row['sellerId']) || $row['parentId']=='0') {} 
		$combo.="<option value='$row[appraiserId]' $selectedText >".$row['APFirstName']." ".$row['APLastName']." </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getLenderCombo($comboName='',$class='',$selectedValue = '', $extra = '',$company) 
{
	$sql = " select * from tbl_lender where status='1' && lenderCompanyId='$company'  "; //&& lenderCompanyId='$company'
	$res = executeQuery($sql); 
	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.=" class='$class'>";
	}else
	{
		$combo.=">";
	}
	$combo.="<option value='' selected>--- Select Lender ---</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['lenderId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$row[lenderId]' $selectedText >".$row['firstName']." ".$row['lastName']."</option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getCategoryName($Id)
 {
  $sql="select category from tbl_category where categoryId=$Id";
  $result=getSingleResult($sql);
  return $result;
 }
function countImage($Id)
 {
  	$sql="select count(imageId) from tbl_image  where productId='$Id' ";
	$result=getSingleResult($sql);
  	return $result;
 }
function countProduct($Id)
 {
  	$sql="select count(productId) from tbl_product  where sellerId='$Id' ";
	$result=getSingleResult($sql);
  	return $result;
 }
function getNoOfProductByPlan($Id)
 {
  	$sql="select noOfProduct from tbl_financial  where financialId='$Id' ";
	$result=getSingleResult($sql);
  	return $result;
 }

function getDateFormat($value)
{
	if(strstr($value,"/"))
	{ 
		$arrDate=@explode("/",$value); //print_r($arrDate);
		$fromTs=mktime(0,0,0,$arrDate[0],$arrDate[1],$arrDate[2]); //mktime(
	}
	else if(strstr($value,"-"))
	{ 
		$arrDate=@explode("-",$value);
		$fromTs=mktime(0,0,0,$arrDate[1],$arrDate[2],$arrDate[0]); 
	}
	else
	{
		$fromTs=$value;
	} 
	return date("M j, Y",$fromTs);
}
function getDateFormat2($value)
{
	if(strstr($value,"/"))
	{ 
		$arrDate=@explode("/",$value); //print_r($arrDate);
		$fromTs=mktime(0,0,0,$arrDate[0],$arrDate[1],$arrDate[2]); //mktime(
	}
	else if(strstr($value,"-"))
	{ 
		$arrDate=@explode("-",$value);
		$fromTs=mktime(0,0,0,$arrDate[1],$arrDate[2],$arrDate[0]); 
	}
	else
	{
		$fromTs=$value;
	} 
	return date("m/d/Y h:i A",$fromTs);
}
function gettime($name,$selected,$class)
	{
		$i=1;
		$time="<select name='$name' class='$class'>";
		//$time.="<option value='' class='txt2'>Time</option>";
		for($i=1;$i<=12;$i++)
		{
		($i<10) ? ($i='0'.$i) : ($i=$i); 
		$time.="<option value='$i' " ;
		if($i==$selected)
		{  
		$time.= "selected";  
		} 
		$time.="> $i </option>";
	} 
	$time.="</select>";
return $time;
} 
function gettimeH($name,$selected,$class)
	{
		$i=1;
		$time="<select name='$name' class='$class'>";
		//$time.="<option value='' class='txt2'>Time</option>";
		/*for($i=0;$i<=59;$i++)
		{
		($i<10) ? ($i='0'.$i) : ($i=$i); 
		$time.="<option value='$i' " ;
		if($i==$selected)
		{  
		$time.= "selected";  
		} 
		$time.="> $i </option>";
		} */
	$time.="<option value='00' ";
	if($selected=='00') 
	{ 
	$time.= " selected"; 
	}
	$time.=">00</option>";
	$time.="<option value='30' ";
	if($selected=='30') 
	{ 
	$time.= " selected"; 
	}
	$time.= ">30</option>";
	$time.="</select>";
return $time;
} 
function getam($name,$selected,$class)
{
	$am="<select name='$name' class='$class'>";
	$am.="<option value='AM' ";
	if($selected=='AM') 
	{ 
	$am.= " selected"; 
	}
	$am.= ">AM</option>";
	$am.="<option value='PM' ";
	if($selected=='PM') 
	{ 
	$am.= " selected"; 
	}
	$am.= ">PM</option>";
	$am.="</select>";	
	return $am;
}

function yearCombo($name='',$start_year='',$end_year='',$class,$selected='')
{
	if($name == ''){
		$name = "year_combo";
	}
	if($end_year==""){
		$end_year=date(Y);
	}

	$ycombo="<select name='$name' class='$class'>";
	$ycombo.="<option value=''>YY</option>";
	for($i=$start_year;$i<=$end_year;$i++){ 
		$ycombo.="<option value='$i' " ;
		if($i==$selected){  
			$ycombo.= "selected";  
		} 
		else if($i==date("Y")){
			$ycombo.="selected ";
		} 
		$ycombo.="> $i </option>";
	} 
	$ycombo.="</select>";
return $ycombo ;

} 

function dateCombo($name='',$class,$selected=''){ 
	if($name == ''){
		$name = "date_combo";
	}
	$dcombo="<select name='$name' class='$class'>";
	$dcombo.="<option value=''>DD</option>";
	for($i=1;$i<=31;$i++){ 
	($i<10) ? ($i='0'.$i) : ($i=$i);
	$day_val=date("d",mktime(0,0,0,1,$i,date("Y")));
	$dcombo.="<option value='$day_val' "; 
		if(abs($i)==$selected) {
			$dcombo.="selected ";
		} 
		else if($day_val==date("d")){
			$dcombo.="selected ";
		} 
	//echo $i =  date("d", strtotime($i));	

		$dcombo.=">$i</option>";
	} 
	$dcombo.="</select>";
	return $dcombo ;

}



function monthCombo($name='',$class,$selected='')
{
	if($name == ''){

		$name = "month_combo";
	}
	//$j=$start_month;
	$mcombo="<select name='$name' class='$class' >";
	$mcombo.="<option value=''>MM</option>";
	for($i=1;$i<=12;$i++){ 
		$mon=date("M",mktime(0,0,0,$i,1,date("Y")));
		//$mon_val=date("m",mktime(0,0,0,$i,1,date("Y")));

		$mcombo.="<option value='$i' ";
		if($mon_val==$selected) { 
			$mcombo.="selected "; 
		}
		else if($mon_val==date("m")){
			$mcombo.="selected ";
		} 
		$mcombo.=">$mon</option>";
	}
	$mcombo.="</select>";
	return $mcombo ;
} 

function removeHtmlchar($value)
{
	$safeValue = htmlentities($value);
	return $safeValue;
}

function getCssBySiteId($Id)
{
		echo $sql = " select templatePath  from tbl_usertemplate A, tbl_template B where A.templateId=B.templateId && A.status = '1' and userId = '$Id' ";
		$res = executeQuery($sql);
		if($row = mysql_fetch_array($res))
		{
			return $row[0];
		}
}
function getRandomTemplateId()
{
	$sql="select templateId from tbl_template where status = '1' order by rand() ";
	return $result = getSingleResult($sql);
}
function getProductName($id)
	{
		$sql="select  productName from tbl_product where productId='$id' ";
		return $result = getSingleResult($sql);
	}
function getLenderCount($Id)
{
	$sql="select count(lenderCompanyId) from tbl_lender where lenderCompanyId = '$Id'";
	return $result = getSingleResult($sql);
}
function getStatus($str)
{
	switch ($str)
	{
		case '1': $show='Unassigned';
					break;
		case '2': $show='Assigned';
					break;
		case '3': $show='Message left';
					break;
		case '4': $show='Suspended Cancelled';
					break;
		case '5': $show='Inspection Scheduled';
					break;
		case '6': $show='Inspection Completed';
					break;
		case '7': $show='To Be reviewed';
					break;
		case '8': $show='Report Complete';
					break;	
		case '9': $show='Revision Needed';
					break;	
		case '10': $show='In Progress';
					break;		
		case '11': $show='Refer To Comments';
					break;		
		case '12': $show='Waiting For FHA Case Number';
					break;
		case '13': $show='Report Being Typed';
					break;
	}
	return $show;
}
function getEmail($Id)
{
	$sql="select  email from tbl_user where userId='$Id' ";
	return $result = getSingleResult($sql);
}
function getAdminEmail($Id)
{
	$sql="select  email from tbl_user where userId='$Id' ";
	return $result = getSingleResult($sql);
}
function getAdminName($Id)
{
	$result="Admin";
	return $result;
}
function getEmailAppraiserByAppraiserId($Id)
{
	$sql="select  email from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}
function getEmailLederByOrderId($Id)
{
	$sql="select  email from tbl_lender A,tbl_order B where A.lenderId=B.orderedBy && orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getNameEmailAppraiserByAppraiserId($Id)
{
	$sql="select  email,APFirstName from tbl_appraiser where appraiserId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
function getNameEmailLederByOrderId($Id)
{
	$sql="select  email,firstName from tbl_lender A,tbl_order B where A.lenderId=B.orderedBy && orderId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
//---------- Account System Functions -----------//
function getOrderbycompanyidByLeder($Id)
{
	$sql="select orderbycompanyid from tbl_lender where lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getOrderbycompanyidByAppraiser($Id)
{
	$sql="select orderbycompanyid from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}

###---------- For Insert New Records ------------###
function getMaxOrderbycompanyidByLeder($Id)
{
	$sql="select max(orderbycompanyid) from tbl_lender ";
	$result = getSingleResult($sql);
	return $result+1;
}
function getMaxOrderbycompanyidByAppraiser($Id)
{
	$sql="select max(orderbycompanyid) from tbl_appraiser ";
	$result = getSingleResult($sql);
	return $result+1;
}
####----------------- END -----------------------###
//---------- END Account System Functions -----------//
function getNameEmailProcesserByOrderId($Id)
{
	$sql="select  email,firstName from tbl_lender A,tbl_order B where A.lenderId=B.processor && orderId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
function getNameEmailProcesser2ByOrderId($Id)
{
	$sql="select  email,firstName from tbl_lender A,tbl_order B where A.lenderId=B.processor2 && orderId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
function getNameEmailAppraiserByOrderId($Id)
{
	$sql="select  email,CONCAT(APFirstName,' ', APLastName) from tbl_appraiser A,tbl_order B where A.appraiserId = B.assignedAppraiser && orderId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
function getNameAppraiserByAppraiserId($Id)
{
	$sql="select  CONCAT(APFirstName,' ', APLastName) from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}
function getAppraiserFess($Id)
{
	$sql="select  APFee from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}
function getAppraiserPhone($Id)
{
	$sql="select  APPHArea,APPHPre,APPHSuf,APPHExt from tbl_appraiser where appraiserId='$Id' ";
	$res = executeQuery($sql);
	$row = mysql_fetch_array($res);
	return $PhStr=$row[0]."-".$row[1]."-".$row[2]."-".$row[3];
}
function getNameLenderByLenderId($Id)
{
	$sql="select  CONCAT(firstName,' ', lastName) from tbl_lender where lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getLenderCompanyId($Id)
{
	$sql="select lendercompanyId from tbl_lender where lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getLenderType($Id)
{
	$sql="select manager from tbl_lender where lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getMyCompanyLenders($Id)
{
	$sql="select lenderId from tbl_lender where lendercompanyId='$Id' ";
	$res = executeQuery($sql);
	$str='';
	while($row = mysql_fetch_array($res))
	{
		$str.=$row[0].",";
	}
	return substr($str,0,-1);
}
function getNameCompanyByCompanyId($Id)
{
	$sql="select  companyName from tbl_lendercompany where lendercompanyId='$Id' ";
	return $result = getSingleResult($sql);
}
function getFileNumberByOrderId($Id)
{
	$sql="select  fileNumber from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getReportPath($Id)
 {
  $sql="select reportPath from tbl_order where orderId='$Id'";
  $result=getSingleResult($sql);
  return $result;
 }
function getCompanyProfile($Id)
{
	$sql="select  companyName,address,city,state,zipcode,phone from tbl_lendercompany where lenderCompanyId='$Id' ";
	$res = executeQuery($sql);
	return $result = $row = mysql_fetch_array($res);
}
function getFilenumber($Id)
{
	$sql="select filenumber from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getBorrowerName($Id)
{
	$sql="select borrower from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getPropertyAddress($Id)
{
	$sql="select propertyAddress,propertyCity,propertyState,propertyZip from tbl_order where orderId='$Id' ";
	$res = executeQuery($sql);
	$row = mysql_fetch_array($res);
	$result = $row[0].", ".$row[1].", ".$row[2].", ".$row[3];
	return $result;
}
function getZipByOrderId($Id)
{
	$sql="select propertyZip from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getLatestComment($Id)
{
	$sql="select comment from tbl_comment where orderId='$Id' order by cmtTms DESC ";
	$result=getSingleResult($sql);
	$arrR = explode(":",$result); //print_r($arrR); exit;
	if($arrR[0]=='Message To')
	{
		$com='Email Message';
	}
	else if($arrR[0]=='Inspection Sceduled')
	{
		$com=$arrR[2].$arrR[3];
	}
	else
	{
		$com=$arrR[2];
	}
	return trim($com);
}
function getNameCompanyBylenderId($Id)
{
	$sql="select  companyName from tbl_lendercompany A,tbl_lender B where A.lenderCompanyId=B.lenderCompanyId && A.lendercompanyId='$Id' ";
	return $result = getSingleResult($sql);
}
function getDFLTODRCMTBylenderId($Id)
{
	$sql="select  Defaut_Order_Comments from tbl_lendercompany A,tbl_lender B where A.lenderCompanyId=B.lenderCompanyId && B.lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getCompanyIdBylenderId($Id)
{
	$sql="select A.lenderCompanyId from tbl_lendercompany A,tbl_lender B where A.lenderCompanyId=B.lenderCompanyId && lenderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getAppraiserCompanyName($Id)
{
	$sql="select APCompany from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}
function getFHACase($Id)
{
	$sql="select FHA from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function getLoanType($Id)
{
	$sql="select loanType from tbl_order where orderId='$Id' ";
	return $result = getSingleResult($sql);
}
function sortArrows($column){
global $_SERVER;
return '<A HREF="'.$_SERVER['PHP_SELF'].getQryStr(array('order_by','order_by2'), array($column,'asc')).'"><IMG SRC="images/blue_up.gif" BORDER="0"></A> <A HREF="'.$_SERVER['PHP_SELF'].getQryStr(array('order_by','order_by2'), array($column,'desc')).'"><IMG SRC="images/blue_down.gif" BORDER="0"></A>';
}
function getQryStr($over_write_key = array(), $over_write_value= array())
{
global $_GET;
$m = $_GET;
if(is_array($over_write_key)){
$i=0;
foreach($over_write_key as $key){
$m[$key] = $over_write_value[$i];
$i++;
}
}else{
$m[$over_write_key] = $over_write_value;
}
$qry_str = qryStr($m);
return $qry_str;
}
function qryStr($arr, $skip = '')
{
$s = "?";
$i = 0;
foreach($arr as $key => $value) {
if ($key != $skip) {
if(is_array($value)){
foreach($value as $value2){
if ($i == 0) {
$s .= "$key%5B%5D=$value2";
$i = 1;
} else {
$s .= "&$key%5B%5D=$value2";
}
}
}else{
if ($i == 0) {
$s .= "$key=$value";
$i = 1;
} else {
$s .= "&$key=$value";
}
}
}
}
return $s;
}
function getConfigSession()
{
	if($_SESSION['sess_config_array'] == '')
	{
		$sql="select * from tbl_config where adminId='$_SESSION[adminId]' ";
		$res = executeQuery($sql);
		$row = mysql_fetch_array($res);
		$_SESSION['sess_config_array'] = $row;
	}
}
function getMCombo($arrName,$comboName='',$class='',$selectedValue = '', $extra = '') 
{
	$combo="<select name='$comboName'  size='20' id='$comboName' multiple ";
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}
	//$combo.="<option value='' selected>-- Select Any --</option>";
	foreach($arrName as $key=>$value)		
	{
		if ($selectedValue == $key) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		$combo.="<option value='$key' $selectedText > $value </option>";
	}
	$combo.="</select>";
	return $combo ;
}
function getOrderStr($type,$order)
{
	if($type=='company')
	{
		$sql = " select lenderCompanyId from tbl_lendercompany order by companyName $order ";
		$res = executeQuery($sql);
		while($row = mysql_fetch_array($res))
		{
			$Stgr_Id.=$row[0].",";
		}
	}
	
	if($type=='orderedBy')
	{
		$sql = " select lenderId from tbl_lender order by firstName $order ";
		$res = executeQuery($sql);
		while($row = mysql_fetch_array($res))
		{
			$Stgr_Id.=$row[0].",";
		}
	}
	if($type=='assignedAppraiser')
	{
		$sql = " select appraiserId from tbl_appraiser order by APFirstName $order ";
		$res = executeQuery($sql);
		while($row = mysql_fetch_array($res))
		{
			$Stgr_Id.=$row[0].",";
		}
	}
	$Stgr_Id=substr($Stgr_Id,0,-1);
	return $Stgr_Id;
}
function isFirstTimeAppraiser($Id)
{
	$sql="select isFirstTime from tbl_appraiser where appraiserId='$Id' ";
	return $result = getSingleResult($sql);
}
function getLincenceNumberOfAppraiser($orderId,$appId)
{
$zip=getZipByOrderId($orderId);
 $sql = " select State from zipcodes where ZipCode='$zip'  ";
 $state = getSingleResult($sql);
 $sql = " select licenseNumber from tbl_appraiserstate where state='$state' && appraiserId='$appId'  ";
 return $licenseNumber = getSingleResult($sql);
}
function getFeeByJobType($JobType,$adminId)
{
 $sql = " select fee from tbl_feeconfig  where jobType='$JobType' && adminId='$adminId'  ";
 $state = getSingleResult($sql);
 return $state;
}


function getNewsletterTemplate($name = '', $class = '', $selected='', $extra='')
{
	$sql="select * from tbl_nl_template where status=1";
	$result=executeQuery($sql);
	$selectOne="--Select Template--";
	$strAlbumCombo = "<select name='$name' class=$class $extra>";
		if($selectOne!="")
		{
			$strAlbumCombo.="<option value=''>".$selectOne."</option>"; 
		}
		while($row=mysql_fetch_array($result)) {
			$strAlbumCombo .= "<option value=\"" . $row[0] . "\"";
			if ($selected == $row[0])
			{ 
				$strAlbumCombo .= " selected ";
			} 
			$strAlbumCombo .= ">" . $row['templateName'] . "</option>";
		} 
		$strAlbumCombo .= "</select>";
	return $strAlbumCombo;
}


function getStateCombo($comboName='',$class='',$selectedValue = '',$extra = '') 
{
	$sql = " select * from tbl_state where status = '1' $sqlCon ";
	$res = executeQuery($sql);

	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}

	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['stateId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		
		$combo.="<option value='$row[stateId]' $selectedText > $row[name] - $row[shortName] </option>";
	}

	$combo.="</select>";
	return $combo ;
}

function getCityCombo($comboName='',$class='',$selectedValue = '',$stateId = '', $extra = '') 
{
	$sql = " select * from tbl_city where status = '1' ";
	
	if($stateId != '')
	{
		$sql.=" and stateId = '$stateId' ";
	}

	$res = executeQuery($sql);

	$combo="<select name='$comboName' id='$comboName' $extra" ;
	if($class != '')
	{
		$combo.="class='$class'>";
	}else
	{
		$combo.=">";
	}

	$combo.="<option value='' selected>Select Any</option>";
	while($row = mysql_fetch_array($res))
	{
		if ($selectedValue == $row['cityId']) 
		{
			$selectedText = "selected";
		}
		else
		{
			$selectedText = '';
		}
		
		$combo.="<option value='$row[cityId]' $selectedText > $row[cityName] </option>";
	}

	$combo.="</select>";
	return $combo ;
}

function getStateName($id)
{
	if(trim($id) != '')
	{
		$sql = "select name from tbl_state where stateId = '$id' ";
		$res = getSingleResult($sql);
		return $res;
	}
}


function getSubStr($str,$length='')
{
	if($length != '')
	{
		$str = substr($str,0,$length);
	}
	else
	{
		$str = substr($str,0,200);
	}

	$str = $str." ...";
	echo $str ;
}
function getStateShortName($id)
{
	if($id)
	{
		$sql="select shortName from  tbl_state where stateId='$id'";
		$result=getSingleResult($sql);
		return $result;
	}
}
function getUserDetail($userId='')
{
    $sql="select * from tbl_user where userId='$userId'";
	$result=executeQuery($sql);
	$row=mysql_fetch_assoc($result);
	return $row;
}

function safe_input($value)
{
	if (get_magic_quotes_gpc())
	{
	  // If magic quotes is enabled - turn the string back into an unsafe string
	  $value = stripslashes($value);
	}
	// Now convert the unsafe string into a MySQL safe string
	$safe_value = mysql_real_escape_string(htmlspecialchars($value)); 
	return $safe_value;
}
function getImagAttributeValue()
{
	echo  $sql="select  template_attributeId  from tbl_template_attribute where templateId='$_SESSION[templateId]' and attribute_type='3'";
	 $result=getSingleResult($sql);
	echo  $sql="select  attributeValue  from tbl_template_attribute_value where attributeId='$result' and userId='$_SESSION[insertUserId]'";
	echo $result=getSingleResult($sql);
	return $result;
}





// Site Specific Functions

function getCourseDropDown($name = '', $class = '', $selected='', $extra='')
{
	$sql="select * from tbl_courses where status=1";
	$result=executeQuery($sql);
	$selectOne="--Select Course--";
	$strAlbumCombo = "<select name='$name' class=$class $extra>";
		if($selectOne!="")
		{
			$strAlbumCombo.="<option value=''>".$selectOne."</option>"; 
		}
		while($row=mysql_fetch_array($result)) {
			$strAlbumCombo .= "<option value=\"" . $row[0] . "\"";
			if ($selected == $row[0])
			{ 
				$strAlbumCombo .= " selected ";
			} 
			$strAlbumCombo .= ">" . $row['name'] . "</option>";
		} 
		$strAlbumCombo .= "</select>";
	return $strAlbumCombo;
}

function getSubjectDropDown($courseId = '', $name = '', $class = '', $selected='', $extra=''){
	if($courseId){
		$sql_str = ' and courseId = "'.$courseId.'" ';
	}
	$sql="select * from tbl_subjects where status=1 ".$sql_str;
	$result=executeQuery($sql);
	$selectOne="--Select Subject--";
	$strAlbumCombo = "<select name='$name' class=$class $extra>";
		if($selectOne!=""){
			$strAlbumCombo.="<option value=''>".$selectOne."</option>"; 
		}
		while($row=mysql_fetch_array($result)) {
			$strAlbumCombo .= "<option value=\"" . $row[0] . "\"";
			if ($selected == $row[0]){ 
				$strAlbumCombo .= " selected ";
			} 
			$strAlbumCombo .= ">" . $row['name'] . "</option>";
		} 
		$strAlbumCombo .= "</select>";
	return $strAlbumCombo;
}


?>